using System;
using System.Collections.Generic;

namespace Phoenix.Storage
{
    public class TransientStore : ITransientStore 
    {
        readonly Dictionary<string, object> store = new Dictionary<string, object>();

        public void Save<T>(string key, T value) where T : class
        {
            store.Add(key, value);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key"></param>
        /// <returns>null if not found, otherwise saved value</returns>
        public T Load<T>(string key) where T : class
        {
            if (store.ContainsKey(key))
            {
                return (T)store[key];
            }

            return null;
        }

        public bool Contains(string key)
        {
            return store.ContainsKey(key);
        }

        public void Remove(string key)
        {
            if (store.ContainsKey(key))
                store.Remove(key);
        }
    }
}